<?php

namespace App\Models\User;

use App\Models\Common\CommonModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class FlyOrder extends CommonModel
{
    use HasFactory;

    protected $table = 'fly_order';

    protected $appends = ['status_name'];

    public function getStatusNameAttribute() {
        return $this->status==1?'待审核':'已审核';
    }

    public function getUser() {
        return $this->belongsTo('App\Models\User\User','user_id','id');
    }

    public function getLst(array $conditions = []) {
        $records = $this->newQuery();
        if(!empty($conditions['name'])) {
            $records = $records->whereHas('getUser',function ($query) use ($conditions) {
                $query->where('name',"like","%{$conditions['name']}%");
            });
        }
        if(!empty($conditions['passport'])) {
            $records = $records->whereHas('getUser',function ($query) use ($conditions) {
                $query->where('passport',$conditions['passport']);
            });
        }
        if(!empty($conditions['phone'])) {
            $records = $records->whereHas('getUser',function ($query) use ($conditions) {
                $query->where('phone',$conditions['phone']);
            });
        }

        if(!empty($conditions['status'])) {
            $records = $records->where('status',$conditions['status']);
        }
        if (!empty($conditions['flyNumber'])) {
            $records = $records->where('fly_number',$conditions['flyNumber']);
        }
        if (!empty($conditions['bookingDate'])) {
            $records = $records->where('booking_date',$conditions['bookingDate']);
        }



        return $records;
    }
}
